import React, {useEffect, useRef,useState} from 'react';
import {GridContent} from '@ant-design/pro-layout';
import {Card,Descriptions} from 'antd';
import ProTable from '@ant-design/pro-table'
import moment from 'moment';
import {
  degreeList,
  employeeTypeList,
  FamilyRelationList,
  genderList,
  inOrgList,
  studyStyleList,
  yesOrNoIntList,
  yesOrNoList,
  relationList,
  employeeStatusList, positionStarList
} from "@/utils/constant";
import {findDictionary} from '@/pages/Info/service';
import { findItemByTree } from '@/utils/functions'
import {queryEmployeeEducationPage,queryEmployeeSocietyexperiencePage,queryEmployeeInorgnamePage,queryFamilyMemberPage,queryRelativeRecordsPage} from '../service';
import {getProfessionstyle} from '@/services/user';

const BasisInfo = (props) => {

  const actionRef = useRef();
  const {info,orgLine,orgSystem,nativePlace} = props;
  const [professional,setProfessional] = useState([]);
  const [degree,setDegree] = useState([]);
  const educationColumns = [
    {
      title: '毕业院校',
      dataIndex: 'school',
      key: 'school',
    },
    {
      title: '所学专业',
      dataIndex: 'speciality',
      key: 'speciality',
    },
    {
      title: '入学时间',
      dataIndex: 'schooldate',
      key: 'schooldate',
      render: (text, record) => {
        return moment(text).format('YYYY-MM-DD')
      },
    },
    {
      title: '毕业时间',
      dataIndex: 'graduatedate',
      key: 'graduatedate',
      render: (text, record) => {
        return moment(text).format('YYYY-MM-DD')
      },
    },
    {
      title: '学习方式',
      dataIndex: 'studystyle',
      key: 'studystyle',
      render: (text, record) => {
        const res = studyStyleList.find((item) => item.value === text);
        return res ? res.label : text
      },
    },
    {
      title: '学历',
      dataIndex: 'grade',
      render: (text) => {
        const res = degreeList.find((item) => item.value === text);
        return res ? res.label : text
      },
    },
    {
      title: '学位',
      dataIndex: 'degree',
      render: (text) => {
        const res = degree.find((item) => item.value === text);
        return res ? res.label : text
      },
    },
    {
      title: '是否最高学历',
      dataIndex: 'istopgrade',
      render: (text) => {
        const res = yesOrNoList.find((item) => item.value === text);
        return res ? res.label : text
      },
    },
    {
      title: '学位证书编号',
      dataIndex: 'degreeNum',
      key: 'degreeNum',
    },
    {
      title: '学历证书编号',
      dataIndex: 'gradeNum',
      key: 'gradeNum',
    },
  ];
  const societyColumns = [
    {
      title: '任职单位',
      dataIndex: 'company',
      key: 'company',
    },
    {
      title: '任职部门',
      dataIndex: 'department',
      key: 'department',
    },
    {
      title: '入职时间',
      dataIndex: 'begindate',
      key: 'begindate',
      render: (text, record) => {
        return moment(text).format('YYYY-MM-DD')
      },
    },
    {
      title: '离职时间',
      dataIndex: 'enddate',
      key: 'enddate',
      render: (text, record) => {
        return moment(text).format('YYYY-MM-DD')
      },
    },
    {
      title: '任职岗位',
      dataIndex: 'responsibility',
      key: 'responsibility',
    },
    {
      title: '证明人',
      dataIndex: 'witness',
      key: 'witness',
    },
    {
      title: '证明人联系方式',
      dataIndex: 'witnesscontact',
      key: 'witnesscontact',
    },
  ];
  const familyColumns = [
    {
      title: '家属姓名',
      dataIndex: 'name',
      key: 'name',
    },
    {
      title: '性别',
      dataIndex: 'gender',
      key: 'gender',
      render: (text, record) => {
        const res = genderList.find((item) => item.value === text)
        return res ? res.label : text
      },
    },
    {
      title: '与本人关系',
      dataIndex: 'relation',
      key: 'relation',
      render: (text, record) => {
        const res = relationList.find((item) => item.value === parseInt(text))
        return res ? res.label : text
      },
    },
    {
      title: '工作单位',
      dataIndex: 'company',
      key: 'company',
    },
    {
      title: '联系号码',
      dataIndex: 'phone',
      key: 'phone',
    },
    {
      title: '是否紧急联系人',
      dataIndex: 'isEmergencyContact',
      key: 'isEmergencyContact',
      render: (text, record) => {
        const res = yesOrNoList.find((item) => item.value === text)
        return res ? res.label : text
      },
    },
  ];
  const relativeRecordsColumns = [
    {
      title: '姓名',
      dataIndex: 'name',
      key: 'name',
    },
    {
      title: '身份证号码',
      dataIndex: 'idcard',
      key: 'idcard',
    },
    {
      title: '任职单位/部门',
      dataIndex: 'unit',
      key: 'unit',
    },
    {
      title: '任职岗位',
      dataIndex: 'job',
      key: 'job',
    },
    {
      title: '关系类别',
      dataIndex: 'relative',
      render: (text) => {
        const res = FamilyRelationList.find((item) => item.value === text)
        return res ? res.label : text
      },
    },
    {
      title: '备注',
      dataIndex: 'isDirectRelative',
    }
  ];
  const inOrgNameColumns = [
    {
      title: '政治面貌',
      dataIndex: 'polity',
      key: 'polity',
      render: (text, record) => {
        const res = inOrgList.find((item) => item.value === text)
        return res ? res.label : text
      },
    },
    {
      title: '加入时间',
      dataIndex: 'joinDay',
      key: 'joinDay',
      render: (text, record) => {
        return (text && text !== '-') ? moment(text).format('YYYY-MM-DD') : '-'
      },
    },
    {
      title: '组织所在单位',
      dataIndex: 'inorgname',
      key: 'inorgname',
    },
  ];

  useEffect(() => {
    getProfessionstyle().then(res =>{
      setProfessional(findItemByTree(res, info.professionalType)?.label);
    });
    findDictionary("CODE_Degree").then(res => {
      setDegree(res);
    });
  }, []);

  return (
    <>
      <GridContent>
        <Card title="任职信息" style={{marginBottom: 24}} bordered={false}>
          <Descriptions>
            <Descriptions.Item label="公司">{info.orgname}</Descriptions.Item>
            <Descriptions.Item label="部门">{info.unitname}</Descriptions.Item>
            <Descriptions.Item
              label="体系">{orgSystem.find(e => info.jobSystemId === e.id)?.name}</Descriptions.Item>
            <Descriptions.Item label="条线">{orgLine.find(e => info.lineId === e.id)?.name}</Descriptions.Item>
            <Descriptions.Item label="工作地点">{info.workAddress}</Descriptions.Item>
            <Descriptions.Item label="职位">{info.jobname}</Descriptions.Item>
            <Descriptions.Item label="工号">{info.code}</Descriptions.Item>
            <Descriptions.Item label="职级">{info.jobLevel}</Descriptions.Item>
            {/*<Descriptions.Item label="招聘类型">{socialTraineeStateArray[info.socialTrainee]}</Descriptions.Item>*/}
            <Descriptions.Item
              label="是否管培生">{yesOrNoIntList.find(e => info.isManagementTrainee === e.value)?.label}</Descriptions.Item>
            <Descriptions.Item
              label="入职日期">{info.hiredate && moment(info.hiredate).format('YYYY-MM-DD')}</Descriptions.Item>
            <Descriptions.Item label="司龄">
              {['3', '4', '5', '6'].indexOf(info.employeestatus) > -1 ? moment(info.dimissionTime).diff(info.hiredate, 'years',true).toFixed(1) + '年' : moment().diff(info.hiredate, 'years',true).toFixed(1) + '年'}
            </Descriptions.Item>
            <Descriptions.Item
              label="员工状态">{employeeStatusList.find(e=>info.employeestatus===e.value)?.label}</Descriptions.Item>
            {/*<Descriptions.Item label="合同期限">{laborContractYearsList.find(e=>info.laborContractYears===e.value)?.label}</Descriptions.Item>*/}
            {/*<Descriptions.Item label="试用期">{probationDayList.find(e => info.probationday === e.value)?.label}</Descriptions.Item>*/}
            <Descriptions.Item
              label="用工类型">{employeeTypeList.find(e => parseInt(info.jobType) === e.value)?.label}</Descriptions.Item>
            {/*<Descriptions.Item label="是否社保异地代缴">{isRemoteSocialSecurityList.find(e => parseInt(info.isRemoteSocialSecurity) === e.value)?.label}</Descriptions.Item>*/}
            {/*<Descriptions.Item label="代缴省市">{resultCityName(nativePlace,info.socialSecurityProvince,info.socialSecurityCity)}</Descriptions.Item>*/}
            <Descriptions.Item label="专业类型">{professional}</Descriptions.Item>
            <Descriptions.Item label="是否复职">{yesOrNoList.find(e => info.reinstatement === e.value)?.label}</Descriptions.Item>
            {/*<Descriptions.Item label="是否中心负责人">{yesOrNoList.find(e => info.iscentreprincipal === e.value)?.label}</Descriptions.Item>*/}
            {/*<Descriptions.Item label="是否部门负责人">{yesOrNoList.find(e => info.isdepartmentprincipa === e.value)?.label}</Descriptions.Item>*/}
            {/*<Descriptions.Item label="档案所在地">{info.recordFileAddress}</Descriptions.Item>*/}
            {/*<Descriptions.Item label="档案编号">{info.fileNumber}</Descriptions.Item>*/}
            <Descriptions.Item label="岗位星级">{positionStarList.find(e => parseInt(info.positionStar) === e.value)?.label}</Descriptions.Item>
          </Descriptions>
        </Card>

        <Card title="教育经历" style={{marginBottom: 24}} bordered={false}>
          <ProTable
            actionRef={actionRef}
            rowKey="oid"
            search={false}
            options={false}
            toolBarRender={false}
            request={(params) => queryEmployeeEducationPage(params,info.oid)}
            columns={educationColumns}
          />
        </Card>

        <Card title="工作经历" style={{marginBottom: 24}} bordered={false}>
          <ProTable
            rowKey="oid"
            search={false}
            options={false}
            toolBarRender={false}
            request={(params) => queryEmployeeSocietyexperiencePage(params,info.oid)}
            columns={societyColumns}
          />
        </Card>

        <Card title="行政党派信息" style={{marginBottom: 24}} bordered={false}>
          <ProTable
            rowKey="oid"
            search={false}
            options={false}
            toolBarRender={false}
            request={(params) => queryEmployeeInorgnamePage(params,info.oid)}
            columns={inOrgNameColumns}
          />
        </Card>

        <Card title="家庭成员信息" style={{marginBottom: 24}} bordered={false}>
          <ProTable
            rowKey="oid"
            search={false}
            options={false}
            toolBarRender={false}
            request={(params) => queryFamilyMemberPage(params,info.oid)}
            columns={familyColumns}
          />
        </Card>

        <Card title="关系报备" style={{marginBottom: 24}} bordered={false}>
          <ProTable
            rowKey="id"
            search={false}
            options={false}
            toolBarRender={false}
            request={(params) => queryRelativeRecordsPage(params,info.oid)}
            columns={relativeRecordsColumns}
          />
        </Card>
      </GridContent>
    </>
  )
};
export default BasisInfo;


